package com.shsxt.controller.base;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.shsxt.dao.AuntDao;
import com.shsxt.dao.BaseDao;
import com.shsxt.dao.OrderDao;
import com.shsxt.dao.WodeDao;
import com.shsxt.dao.YuyueDao;
import com.shsxt.model.BaseQuery;
import com.shsxt.model.Cbig;
import com.shsxt.model.Dbig;
import com.shsxt.model.Jbig;
import com.shsxt.model.Kbig;
import com.shsxt.model.Rbig;
import com.shsxt.model.Sbig;
import com.shsxt.model.ServicePersonalbig;
import com.shsxt.model.UserInfobig;
import com.shsxt.model.Zbig;
import com.shsxt.service.AuntService;
import com.shsxt.service.OrderService;
import com.shsxt.vo.AuntOrderQuery;
import com.shsxt.vo.OrderQuery;
import com.shsxt.vo.WithdrawBig;

public abstract class BaseService<T> {
	
	@Autowired
	private BaseDao<T> baseDao;
	@Autowired
	private WodeDao wodeDao;
	@Autowired
	private AuntDao auntDao;
	@Autowired
	private YuyueDao yuyueDao;
	@Autowired
	private AuntService auntService;
	@Autowired
	private OrderService orderService;
	 public Map<String, Object> testselectForPage(BaseQuery query,String state) throws ParseException {
	        Map<String, Object> result = new HashMap<String, Object>();
		  	PageList<T> pageDatas = null;	
		  	
		  	if(state.equals("1")){
			
		  		List<Rbig> list=new ArrayList();
				list= baseDao.rselectForPage(query, query.toPageBounds());
			 for(Rbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("2")){
		  		List<Sbig> list=new ArrayList();
				list= baseDao.sselectForPage(query, query.toPageBounds());
			 for(Sbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }
				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("3")){
		  		List<Kbig> list=new ArrayList();
				list= baseDao.kselectForPage(query, query.toPageBounds());
			 for(Kbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("4")){
		  		List<Jbig> list=new ArrayList();
				list= baseDao.jselectForPage(query, query.toPageBounds());
			 for(Jbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("5")){
		  		List<Dbig> list=new ArrayList();
				list= baseDao.dselectForPage(query, query.toPageBounds());
			 for(Dbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("6")){
		  		List<Cbig> list=new ArrayList();
				list= baseDao.cselectForPage(query, query.toPageBounds());
			 for(Cbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("7")){
		  		List<Zbig> list=new ArrayList();
				list= baseDao.zselectForPage(query, query.toPageBounds());
			 for(Zbig ob:list){
				 String phoneNumber=ob.getPhoneNumber();
				 String redeemCode=ob.getRedeemCode();
				 String servicePersonal=ob.getServicePersonal();
				 ob.setPetName(wodeDao.findUserByPhone(phoneNumber).getPetName());
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				 if(redeemCode.equals("无")){
					 ob.setDisCount("0");
				 }else{
					 ob.setDisCount(yuyueDao.findCouponByRedeemCode(redeemCode).getDiscountAmount());
				 }
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("8")){
				 pageDatas=(PageList<T>) baseDao.yselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("9")){
				 pageDatas=(PageList<T>) baseDao.bselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("21")){
		  		List<UserInfobig> list=new ArrayList();
				list= baseDao.userMessageselectForPage(query, query.toPageBounds());
			 for(UserInfobig ob:list){
				Map<String,Object> map= orderService.findAllOrder(ob.getPhoneNumber());
				List<OrderQuery> listall=new ArrayList<OrderQuery>();
				listall=(List<OrderQuery>) map.get("allorder");
				 List<String> orderNumbers=new ArrayList<String>();
				for(OrderQuery oq:listall){
					orderNumbers.add(oq.getType()+":"+oq.getOrderNumber());
				}
				
					 ob.setOrderNumbers(orderNumbers);
					 System.err.println("XXXX"+ob.toString());
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("22")){
		  		List<ServicePersonalbig> list=new ArrayList();
				list= baseDao.auntMessageselectForPage(query, query.toPageBounds());
			 for(ServicePersonalbig ob:list){
				Map<String,Object> map= auntService.all(ob.getPhoneNumber());
				List<AuntOrderQuery> listall=new ArrayList<AuntOrderQuery>();
				listall=(List<AuntOrderQuery>) map.get("list");
				 List<String> orderNumbers=new ArrayList<String>();
				for(AuntOrderQuery aq:listall){
					orderNumbers.add(aq.getType()+":"+aq.getOrderNumber());
				}
				
					 ob.setOrderNumbers(orderNumbers);
					 System.err.println("XXXX"+ob.toString());
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("23")){
				 pageDatas=(PageList<T>) baseDao.userFeedselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("24")){
				 pageDatas=(PageList<T>) baseDao.auntFeedselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("25")){
				 pageDatas=(PageList<T>) baseDao.locationselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("31")){
		  		List<WithdrawBig> list=new ArrayList();
				list= baseDao.withdrawselectForPage(query, query.toPageBounds());
			 for(WithdrawBig ob:list){
				 String servicePersonal=ob.getAunt();
				 if(auntDao.findAuntByServicePersonal(servicePersonal)==null||auntDao.findAuntByServicePersonal(servicePersonal).equals("")){
					 ob.setAuntName("暂无阿姨");
				 }else{
					 ob.setAuntName(auntDao.findAuntByServicePersonal(servicePersonal).getName());
				 }				
			 }
			  pageDatas=(PageList<T>) list;
			 result.put("rows", pageDatas);
		        result.put("total", pageDatas.getPaginator().getTotalCount());
		        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("32")){
				 pageDatas=(PageList<T>) baseDao.tongjiselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("41")){
				 pageDatas=(PageList<T>) baseDao.cdkeyselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("42")){
				 pageDatas=(PageList<T>) baseDao.couponselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("51")){
				 pageDatas=(PageList<T>) baseDao.notifiedselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}else if(state.equals("52")){
				 pageDatas=(PageList<T>) baseDao.activityselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}
		  	else if(state.equals("53")){
				 pageDatas=(PageList<T>) baseDao.lunboselectForPage(query, query.toPageBounds());
				 result.put("rows", pageDatas);
			        result.put("total", pageDatas.getPaginator().getTotalCount());
			        result.put("paginator", pageDatas.getPaginator());
		  	}
		  	
		  	
		  	
		  	
	        return result;
	    }
	
}
